#include <FileTypes.h>

using namespace std;

pthread_mutex_t FileTypes::_mutex = PTHREAD_MUTEX_INITIALIZER;
FileTypes* FileTypes::_instance = NULL;

FileTypes::FileTypes()
{
    Init();
}

bool FileTypes::Exists(string fileExt) const
{
    return (_extToTypes.find(fileExt) != _extToTypes.end());
}

string FileTypes::GetType(string fileExt)
{
    if (_extToTypes.find(fileExt) == _extToTypes.end())
    {
        return STREAM_TYPE;
    }
    return string(_extToTypes[fileExt]);
}

FileTypes* FileTypes::Instance()
{
    if (_instance == NULL)
    {
        pthread_mutex_lock(&_mutex);
        if (_instance == NULL)
        {
            _instance = new FileTypes();
        }
        pthread_mutex_unlock(&_mutex);
    }

    return _instance;
}

void FileTypes::Init()
{
    _extToTypes["001"]="application/x-001";
    _extToTypes["301"]="application/x-301";
    _extToTypes["323"]="text/h323";
    _extToTypes["906"]="application/x-906";
    _extToTypes["907"]="drawing/907";
    _extToTypes["a11"]="application/x-a11";
    _extToTypes["acp"]="audio/x-mei-aac";
    _extToTypes["ai"]="application/postscript";
    _extToTypes["aif"]="audio/aiff";
    _extToTypes["aifc"]="audio/aiff";
    _extToTypes["aiff"]="audio/aiff";
    _extToTypes["anv"]="application/x-anv";
    _extToTypes["asa"]="text/asa";
    _extToTypes["asf"]="video/x-ms-asf";
    _extToTypes["asp"]="text/asp";
    _extToTypes["asx"]="video/x-ms-asf";
    _extToTypes["au"]="audio/basic";
    _extToTypes["avi"]="video/avi";
    _extToTypes["awf"]="application/vnd.adobe.workflow";
    _extToTypes["biz"]="text/xml";
    _extToTypes["bmp"]="application/x-bmp";
    _extToTypes["bot"]="application/x-bot";
    _extToTypes["c4t"]="application/x-c4t";
    _extToTypes["c90"]="application/x-c90";
    _extToTypes["cal"]="application/x-cals";
    _extToTypes["cat"]="application/s-pki.seccat";
    _extToTypes["cdf"]="application/x-netcdf";
    _extToTypes["cdr"]="application/x-cdr";
    _extToTypes["cel"]="application/x-cel";
    _extToTypes["cer"]="application/x-x509-ca-cert";
    _extToTypes["cg4"]="application/x-g4";
    _extToTypes["cgm"]="application/x-cgm";
    _extToTypes["cit"]="application/x-cit";
    _extToTypes["class"]="java/*";
    _extToTypes["cml"]="text/xml";
    _extToTypes["cmp"]="application/x-cmp";
    _extToTypes["cmx"]="application/x-cmx";
    _extToTypes["cot"]="application/x-cot";
    _extToTypes["crl"]="application/pkix-crl";
    _extToTypes["crt"]="application/x-x509-ca-cert";
    _extToTypes["csi"]="application/x-csi";
    _extToTypes["css"]="text/css";
    _extToTypes["cut"]="application/x-cut";
    _extToTypes["dbf"]="application/x-dbf";
    _extToTypes["dbm"]="application/x-dbm";
    _extToTypes["dbx"]="application/x-dbx";
    _extToTypes["dcd"]="text/xml";
    _extToTypes["dcx"]="application/x-dcx";
    _extToTypes["der"]="application/x-x509-ca-cert";
    _extToTypes["dgn"]="application/x-dgn";
    _extToTypes["dib"]="application/x-dib";
    _extToTypes["dll"]="application/x-msdownload";
    _extToTypes["doc"]="application/msword";
    _extToTypes["dot"]="application/msword";
    _extToTypes["drw"]="application/x-drw";
    _extToTypes["dtd"]="text/xml";
    _extToTypes["dwf"]="Model/vnd.dwf";
    _extToTypes["dwf"]="application/x-dwf";
    _extToTypes["dwg"]="application/x-dwg";
    _extToTypes["dxb"]="application/x-dxb";
    _extToTypes["dxf"]="application/x-dxf";
    _extToTypes["edn"]="application/vnd.adobe.edn";
    _extToTypes["emf"]="application/x-emf";
    _extToTypes["eml"]="message/rfc822";
    _extToTypes["ent"]="text/xml";
    _extToTypes["epi"]="application/x-epi";
    _extToTypes["eps"]="application/x-ps";
    _extToTypes["eps"]="application/postscript";
    _extToTypes["etd"]="application/x-ebx";
    _extToTypes["exe"]="application/x-msdownload";
    _extToTypes["fax"]="image/fax";
    _extToTypes["fdf"]="application/vnd.fdf";
    _extToTypes["fif"]="application/fractals";
    _extToTypes["fo"]="text/xml";
    _extToTypes["frm"]="application/x-frm";
    _extToTypes["g4"]="application/x-g4";
    _extToTypes["gbr"]="application/x-gbr";
    _extToTypes["gcd"]="application/x-gcd";
    _extToTypes["gif"]="image/gif";
    _extToTypes["gl2"]="application/x-gl2";
    _extToTypes["gp4"]="application/x-gp4";
    _extToTypes["hgl"]="application/x-hgl";
    _extToTypes["hmr"]="application/x-hmr";
    _extToTypes["hpg"]="application/x-hpgl";
    _extToTypes["hpl"]="application/x-hpl";
    _extToTypes["hqx"]="application/mac-binhex40";
    _extToTypes["hrf"]="application/x-hrf";
    _extToTypes["hta"]="application/hta";
    _extToTypes["htc"]="text/x-component";
    _extToTypes["htm"]="text/html";
    _extToTypes["html"]="text/html";
    _extToTypes["htt"]="text/webviewhtml";
    _extToTypes["htx"]="text/html";
    _extToTypes["icb"]="application/x-icb";
    _extToTypes["ico"]="image/x-icon";
    _extToTypes["ico"]="application/x-ico";
    _extToTypes["iff"]="application/x-iff";
    _extToTypes["ig4"]="application/x-g4";
    _extToTypes["igs"]="application/x-igs";
    _extToTypes["iii"]="application/x-iphone";
    _extToTypes["img"]="application/x-img";
    _extToTypes["ins"]="application/x-internet-signup";
    _extToTypes["isp"]="application/x-internet-signup";
    _extToTypes["IVF"]="video/x-ivf";
    _extToTypes["java"]="java/*";
    _extToTypes["jfif"]="image/jpeg";
    _extToTypes["jpe"]="image/jpeg";
    _extToTypes["jpe"]="application/x-jpe";
    _extToTypes["jpeg"]="image/jpeg";
    _extToTypes["jpg"]="image/jpeg";
    _extToTypes["jpg"]="application/x-jpg";
    _extToTypes["js"]="application/x-javascript";
    _extToTypes["jsp"]="text/html";
    _extToTypes["la1"]="audio/x-liquid-file";
    _extToTypes["lar"]="application/x-laplayer-reg";
    _extToTypes["latex"]="application/x-latex";
    _extToTypes["lavs"]="audio/x-liquid-secure";
    _extToTypes["lbm"]="application/x-lbm";
    _extToTypes["lmsff"]="audio/x-la-lms";
    _extToTypes["ls"]="application/x-javascript";
    _extToTypes["ltr"]="application/x-ltr";
    _extToTypes["m1v"]="video/x-mpeg";
    _extToTypes["m2v"]="video/x-mpeg";
    _extToTypes["m3u"]="audio/mpegurl";
    _extToTypes["m4e"]="video/mpeg4";
    _extToTypes["mac"]="application/x-mac";
    _extToTypes["man"]="application/x-troff-man";
    _extToTypes["math"]="text/xml";
    _extToTypes["mdb"]="application/msaccess";
    _extToTypes["mdb"]="application/x-mdb";
    _extToTypes["mfp"]="application/x-shockwave-flash";
    _extToTypes["mht"]="message/rfc822";
    _extToTypes["mhtml"]="message/rfc822";
    _extToTypes["mi"]="application/x-mi";
    _extToTypes["mid"]="audio/mid";
    _extToTypes["midi"]="audio/mid";
    _extToTypes["mil"]="application/x-mil";
    _extToTypes["mml"]="text/xml";
    _extToTypes["mnd"]="audio/x-musicnet-download";
    _extToTypes["mns"]="audio/x-musicnet-stream";
    _extToTypes["mocha"]="application/x-javascript";
    _extToTypes["movie"]="video/x-sgi-movie";
    _extToTypes["mp1"]="audio/mp1";
    _extToTypes["mp2"]="audio/mp2";
    _extToTypes["mp2v"]="video/mpeg";
    _extToTypes["mp3"]="audio/mp3";
    _extToTypes["mp4"]="video/mpeg4";
    _extToTypes["mpa"]="video/x-mpg";
    _extToTypes["mpd"]="application/-project";
    _extToTypes["mpe"]="video/x-mpeg";
    _extToTypes["mpeg"]="video/mpg";
    _extToTypes["mpg"]="video/mpg";
    _extToTypes["mpga"]="audio/rn-mpeg";
    _extToTypes["mpp"]="application/-project";
    _extToTypes["mps"]="video/x-mpeg";
    _extToTypes["mpt"]="application/-project";
    _extToTypes["mpv"]="video/mpg";
    _extToTypes["mpv2"]="video/mpeg";
    _extToTypes["mpw"]="application/s-project";
    _extToTypes["mpx"]="application/-project";
    _extToTypes["mtx"]="text/xml";
    _extToTypes["mxp"]="application/x-mmxp";
    _extToTypes["net"]="image/pnetvue";
    _extToTypes["nrf"]="application/x-nrf";
    _extToTypes["nws"]="message/rfc822";
    _extToTypes["odc"]="text/x-ms-odc";
    _extToTypes["out"]="application/x-out";
    _extToTypes["p10"]="application/pkcs10";
    _extToTypes["p12"]="application/x-pkcs12";
    _extToTypes["p7b"]="application/x-pkcs7-certificates";
    _extToTypes["p7c"]="application/pkcs7-mime";
    _extToTypes["p7m"]="application/pkcs7-mime";
    _extToTypes["p7r"]="application/x-pkcs7-certreqresp";
    _extToTypes["p7s"]="application/pkcs7-signature";
    _extToTypes["pc5"]="application/x-pc5";
    _extToTypes["pci"]="application/x-pci";
    _extToTypes["pcl"]="application/x-pcl";
    _extToTypes["pcx"]="application/x-pcx";
    _extToTypes["pdf"]="application/pdf";
    _extToTypes["pdf"]="application/pdf";
    _extToTypes["pdx"]="application/vnd.adobe.pdx";
    _extToTypes["pfx"]="application/x-pkcs12";
    _extToTypes["pgl"]="application/x-pgl";
    _extToTypes["pic"]="application/x-pic";
    _extToTypes["pko"]="application-pki.pko";
    _extToTypes["pl"]="application/x-perl";
    _extToTypes["plg"]="text/html";
    _extToTypes["pls"]="audio/scpls";
    _extToTypes["plt"]="application/x-plt";
    _extToTypes["png"]="image/png";
    _extToTypes["png"]="application/x-png";
    _extToTypes["pot"]="applications-powerpoint";
    _extToTypes["ppa"]="application/vs-powerpoint";
    _extToTypes["ppm"]="application/x-ppm";
    _extToTypes["pps"]="application-powerpoint";
    _extToTypes["ppt"]="applications-powerpoint";
    _extToTypes["ppt"]="application/x-ppt";
    _extToTypes["pr"]="application/x-pr";
    _extToTypes["prf"]="application/pics-rules";
    _extToTypes["prn"]="application/x-prn";
    _extToTypes["prt"]="application/x-prt";
    _extToTypes["ps"]="application/x-ps";
    _extToTypes["ps"]="application/postscript";
    _extToTypes["ptn"]="application/x-ptn";
    _extToTypes["pwz"]="application/powerpoint";
    _extToTypes["r3t"]="text/vnd.rn-realtext3d";
    _extToTypes["ra"]="audio/vnd.rn-realaudio";
    _extToTypes["ram"]="audio/x-pn-realaudio";
    _extToTypes["ras"]="application/x-ras";
    _extToTypes["rat"]="application/rat-file";
    _extToTypes["rdf"]="text/xml";
    _extToTypes["rec"]="application/vnd.rn-recording";
    _extToTypes["red"]="application/x-red";
    _extToTypes["rgb"]="application/x-rgb";
    _extToTypes["rjs"]="application/vnd.rn-realsystem-rjs";
    _extToTypes["rjt"]="application/vnd.rn-realsystem-rjt";
    _extToTypes["rlc"]="application/x-rlc";
    _extToTypes["rle"]="application/x-rle";
    _extToTypes["rm"]="application/vnd.rn-realmedia";
    _extToTypes["rmf"]="application/vnd.adobe.rmf";
    _extToTypes["rmi"]="audio/mid";
    _extToTypes["rmj"]="application/vnd.rn-realsystem-rmj";
    _extToTypes["rmm"]="audio/x-pn-realaudio";
    _extToTypes["rmp"]="application/vnd.rn-rn_music_package";
    _extToTypes["rms"]="application/vnd.rn-realmedia-secure";
    _extToTypes["rmvb"]="application/vnd.rn-realmedia-vbr";
    _extToTypes["rmx"]="application/vnd.rn-realsystem-rmx";
    _extToTypes["rnx"]="application/vnd.rn-realplayer";
    _extToTypes["rp"]="image/vnd.rn-realpix";
    _extToTypes["rpm"]="audio/x-pn-realaudio-plugin";
    _extToTypes["rsml"]="application/vnd.rn-rsml";
    _extToTypes["rt"]="text/vnd.rn-realtext";
    _extToTypes["rtf"]="application/msword";
    _extToTypes["rtf"]="application/x-rtf";
    _extToTypes["rv"]="video/vnd.rn-realvideo";
    _extToTypes["sam"]="application/x-sam";
    _extToTypes["sat"]="application/x-sat";
    _extToTypes["sdp"]="application/sdp";
    _extToTypes["sdw"]="application/x-sdw";
    _extToTypes["sit"]="application/x-stuffit";
    _extToTypes["slb"]="application/x-slb";
    _extToTypes["sld"]="application/x-sld";
    _extToTypes["slk"]="drawing/x-slk";
    _extToTypes["smi"]="application/smil";
    _extToTypes["smil"]="application/smil";
    _extToTypes["smk"]="application/x-smk";
    _extToTypes["snd"]="audio/basic";
    _extToTypes["sol"]="text/plain";
    _extToTypes["sor"]="text/plain";
    _extToTypes["spc"]="application/x-pkcs7-certificates";
    _extToTypes["spl"]="application/futuresplash";
    _extToTypes["spp"]="text/xml";
    _extToTypes["ssm"]="application/streamingmedia";
    _extToTypes["sst"]="application-pki.certstore";
    _extToTypes["stl"]="application/-pki.stl";
    _extToTypes["stm"]="text/html";
    _extToTypes["sty"]="application/x-sty";
    _extToTypes["svg"]="text/xml";
    _extToTypes["swf"]="application/x-shockwave-flash";
    _extToTypes["tdf"]="application/x-tdf";
    _extToTypes["tg4"]="application/x-tg4";
    _extToTypes["tga"]="application/x-tga";
    _extToTypes["tif"]="image/tiff";
    _extToTypes["tif"]="application/x-tif";
    _extToTypes["tiff"]="image/tiff";
    _extToTypes["tld"]="text/xml";
    _extToTypes["top"]="drawing/x-top";
    _extToTypes["torrent"]="application/x-bittorrent";
    _extToTypes["tsd"]="text/xml";
    _extToTypes["txt"]="text/plain";
    _extToTypes["uin"]="application/x-icq";
    _extToTypes["uls"]="text/iuls";
    _extToTypes["vcf"]="text/x-vcard";
    _extToTypes["vda"]="application/x-vda";
    _extToTypes["vdx"]="application/vnd.visio";
    _extToTypes["vml"]="text/xml";
    _extToTypes["vpg"]="application/x-vpeg005";
    _extToTypes["vsd"]="application/vnd.visio";
    _extToTypes["vsd"]="application/x-vsd";
    _extToTypes["vss"]="application/vnd.visio";
    _extToTypes["vst"]="application/vnd.visio";
    _extToTypes["vst"]="application/x-vst";
    _extToTypes["vsw"]="application/vnd.visio";
    _extToTypes["vsx"]="application/vnd.visio";
    _extToTypes["vtx"]="application/vnd.visio";
    _extToTypes["vxml"]="text/xml";
    _extToTypes["wav"]="audio/wav";
    _extToTypes["wax"]="audio/x-ms-wax";
    _extToTypes["wb1"]="application/x-wb1";
    _extToTypes["wb2"]="application/x-wb2";
    _extToTypes["wb3"]="application/x-wb3";
    _extToTypes["wbmp"]="image/vnd.wap.wbmp";
    _extToTypes["wiz"]="application/msword";
    _extToTypes["wk3"]="application/x-wk3";
    _extToTypes["wk4"]="application/x-wk4";
    _extToTypes["wkq"]="application/x-wkq";
    _extToTypes["wks"]="application/x-wks";
    _extToTypes["wm"]="video/x-ms-wm";
    _extToTypes["wma"]="audio/x-ms-wma";
    _extToTypes["wmd"]="application/x-ms-wmd";
    _extToTypes["wmf"]="application/x-wmf";
    _extToTypes["wml"]="text/vnd.wap.wml";
    _extToTypes["wmv"]="video/x-ms-wmv";
    _extToTypes["wmx"]="video/x-ms-wmx";
    _extToTypes["wmz"]="application/x-ms-wmz";
    _extToTypes["wp6"]="application/x-wp6";
    _extToTypes["wpd"]="application/x-wpd";
    _extToTypes["wpg"]="application/x-wpg";
    _extToTypes["wpl"]="application/-wpl";
    _extToTypes["wq1"]="application/x-wq1";
    _extToTypes["wr1"]="application/x-wr1";
    _extToTypes["wri"]="application/x-wri";
    _extToTypes["wrk"]="application/x-wrk";
    _extToTypes["ws"]="application/x-ws";
    _extToTypes["ws2"]="application/x-ws";
    _extToTypes["wsc"]="text/scriptlet";
    _extToTypes["wsdl"]="text/xml";
    _extToTypes["wvx"]="video/x-ms-wvx";
    _extToTypes["xdp"]="application/vnd.adobe.xdp";
    _extToTypes["xdr"]="text/xml";
    _extToTypes["xfd"]="application/vnd.adobe.xfd";
    _extToTypes["xfdf"]="application/vnd.adobe.xfdf";
    _extToTypes["xhtml"]="text/html";
    _extToTypes["xls"]="application/-excel";
    _extToTypes["xls"]="application/x-xls";
    _extToTypes["xlw"]="application/x-xlw";
    _extToTypes["xml"]="text/xml";
    _extToTypes["xpl"]="audio/scpls";
    _extToTypes["xq"]="text/xml";
    _extToTypes["xql"]="text/xml";
    _extToTypes["xquery"]="text/xml";
    _extToTypes["xsd"]="text/xml";
    _extToTypes["xsl"]="text/xml";
    _extToTypes["xslt"]="text/xml";
    _extToTypes["xwd"]="application/x-xwd";
    _extToTypes["x_b"]="application/x-x_b";
    _extToTypes["x_t"]="application/x-x_t";
}
